namespace Contoso.Migrations
{
    using System.Data.Entity.Migrations;
    
    public partial class test : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "Course",
                c => new
                    {
                        CourseID = c.Int(nullable: false),
                        Title = c.String(nullable: false, maxLength: 50),
                        Credits = c.Int(nullable: false),
                        DepartmentID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.CourseID)
                .ForeignKey("Department", t => t.DepartmentID, cascadeDelete: true)
                .Index(t => t.DepartmentID);
            
            CreateTable(
                "Department",
                c => new
                    {
                        DepartmentID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                        Budget = c.Decimal(nullable: false, storeType: "money"),
                        StartDate = c.DateTime(nullable: false),
                        InstructorID = c.Int(),
                    })
                .PrimaryKey(t => t.DepartmentID)
                .ForeignKey("Instructor", t => t.InstructorID)
                .Index(t => t.InstructorID);
            
            CreateTable(
                "Instructor",
                c => new
                    {
                        InstructorID = c.Int(nullable: false, identity: true),
                        LastName = c.String(nullable: false, maxLength: 50),
                        FirstName = c.String(nullable: false, maxLength: 50),
                        HireDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.InstructorID);
            
            CreateTable(
                "OfficeAssignment",
                c => new
                    {
                        InstructorID = c.Int(nullable: false),
                        Location = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.InstructorID)
                .ForeignKey("Instructor", t => t.InstructorID)
                .Index(t => t.InstructorID);
            
            CreateTable(
                "Enrollment",
                c => new
                    {
                        EnrollmentID = c.Int(nullable: false, identity: true),
                        CourseID = c.Int(nullable: false),
                        Grade = c.Decimal(precision: 18, scale: 2),
                        StudentID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.EnrollmentID)
                .ForeignKey("Course", t => t.CourseID, cascadeDelete: true)
                .ForeignKey("Student", t => t.StudentID, cascadeDelete: true)
                .Index(t => t.CourseID)
                .Index(t => t.StudentID);
            
            CreateTable(
                "Student",
                c => new
                    {
                        StudentID = c.Int(nullable: false, identity: true),
                        LastName = c.String(nullable: false, maxLength: 50),
                        FirstName = c.String(nullable: false, maxLength: 50),
                        EnrollmentDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.StudentID);
            
            CreateTable(
                "CourseInstructor",
                c => new
                    {
                        CourseID = c.Int(nullable: false),
                        InstructorID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.CourseID, t.InstructorID })
                .ForeignKey("Course", t => t.CourseID, cascadeDelete: true)
                .ForeignKey("Instructor", t => t.InstructorID, cascadeDelete: true)
                .Index(t => t.CourseID)
                .Index(t => t.InstructorID);
            
        }
        
        public override void Down()
        {
            DropIndex("CourseInstructor", new[] { "InstructorID" });
            DropIndex("CourseInstructor", new[] { "CourseID" });
            DropIndex("Enrollment", new[] { "StudentID" });
            DropIndex("Enrollment", new[] { "CourseID" });
            DropIndex("OfficeAssignment", new[] { "InstructorID" });
            DropIndex("Department", new[] { "InstructorID" });
            DropIndex("Course", new[] { "DepartmentID" });
            DropForeignKey("CourseInstructor", "InstructorID", "Instructor");
            DropForeignKey("CourseInstructor", "CourseID", "Course");
            DropForeignKey("Enrollment", "StudentID", "Student");
            DropForeignKey("Enrollment", "CourseID", "Course");
            DropForeignKey("OfficeAssignment", "InstructorID", "Instructor");
            DropForeignKey("Department", "InstructorID", "Instructor");
            DropForeignKey("Course", "DepartmentID", "Department");
            DropTable("CourseInstructor");
            DropTable("Student");
            DropTable("Enrollment");
            DropTable("OfficeAssignment");
            DropTable("Instructor");
            DropTable("Department");
            DropTable("Course");
        }
    }
}
